﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using VanTaiBLL;
using VanTaiData;
using VanTaiProperty;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
using Roles;
using System.Data.SqlTypes;

namespace VanTaiTMS.Page
{
    public partial class thong_tin_xe_ra_vao : System.Web.UI.Page
    {
        #region[Define]
        private DataTable dtVehicleInOut;
        private DataTable dtVehicleInOutDetail_Edit;
        private DataTable dtVehicle;
        private DataTable dtCustomer;
        private DataTable dtCustomerDetail;
        private DataTable dtEmployer;

        private DataTable dtFilter;
        private DataTable dtFillterTrangThai;

        private DataTable dtSearch;
        protected string SuggestionList;
        protected string StrAlert = "";
        private DataTable dtAutoComplete;
        private static bool flag = false;


        private clsTMVehicleInfo_In_OutBusiness clsVehicleInOut = new clsTMVehicleInfo_In_OutBusiness();
        private clsTMVehicleBusiness clsVehicle = new clsTMVehicleBusiness();
        private clsTMCustomersBusiness clsCustomer = new clsTMCustomersBusiness();
        private clsTMMemberBusiness clsEmployer = new clsTMMemberBusiness();
        #endregion

        #region[Controller]
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckPermisstion();
            txtMaKhachHang.ReadOnly = true;
            Autocomplate();
            lbDatetime.Text = DateTime.Now.ToString();
            if (!IsPostBack)
            {
                BindGridVehicleInOut();
                BindGridNumberVehicle();
                BindGridCustomer();
                BindGridEmployer();

                
            }
        }
        protected void cmdAddNew_Click(object sender, EventArgs e)
        {
            flag = true;
            lbThongBaoLoi.Text = "";
            ClearTextbox();
            OpenDialog("#thongtinravaocuaxe");
            imgSave.ToolTip = "Thêm mới";
            upNewUpdatePanel.Update();
            imgSave.Visible = true;
        }
        protected void cmdEdit_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < ListViewAll.Items.Count; i++)
            {
                CheckBox chkView = (CheckBox)ListViewAll.Items[i].FindControl("chkList");
                Label lbTrangThai = (Label)ListViewAll.Items[i].FindControl("lbDuyet");
                if (chkView != null)
                {
                    if (chkView.Checked)
                    {
                        BindGridVehicleInOutDetail_Edit(Convert.ToInt32(ListViewAll.DataKeys[i].Value.ToString()));
                        OpenDialog("#thongtinravaocuaxe");
                        upNewUpdatePanel.Update();
                        imgSave.ToolTip = "Cập nhật";
                        flag = false;
                    }
                }
            }
        }
        protected void cmdDel_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < ListViewAll.Items.Count; i++)
            {
                CheckBox chkHide = (CheckBox)ListViewAll.Items[i].FindControl("chkList");
                Label lbTrangThai = (Label)ListViewAll.Items[i].FindControl("lbDuyet");
                if (chkHide != null)
                {
                    if (chkHide.Checked)
                    {
                        try
                        {
                            VanTaiBLL.clsTMVehicleInfo_In_OutBusiness.DeleteTMVehicleInfo_In_Out(int.Parse(ListViewAll.DataKeys[i].Value.ToString()));
                        }
                        catch (Exception ex)
                        {
                            lbThongBaoXoa.Text = ex.ToString();
                            OpenDialog("#thongbaoxoa");
                            upDatePanelThongBaoXoa.Update();
                            cmdAgree.Visible = false;
                            cmdClose.Text = "Đóng lại";
                        }
                    }
                }
            }
        }
        protected void cmdSerach_Click(object sender, EventArgs e)
        {
            if (txtSearch.Text == "")
            {
                StrAlert += "<div class='alert alert-warning'>";
                StrAlert += "<a href='#' class='close' data-dismiss='alert'>&times;</a>";
                StrAlert += "Vui lòng nhập vào từ khoá để tìm kiếm !";
                StrAlert += "</div>";
            }
            else
            {
                Search(txtSearch.Text);
            }
        }
        protected void cmdRefesh_Click(object sender, EventArgs e)
        {
            txtSearch.Text = "";
            txtTuNgayNgayNhapKho.Text = "";
            txtDenNgayNhapKho.Text = "";
            ClearTextbox();
            BindGridVehicleInOut();
        }
        protected void cmdFilter_Click(object sender, EventArgs e)
        {
            Fillter(txtTuNgayNgayNhapKho.Text, txtDenNgayNhapKho.Text);
        }
        protected void cmdDuyet_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < ListViewAll.Items.Count; i++)
            {
                CheckBox chkHide = (CheckBox)ListViewAll.Items[i].FindControl("chkList");
                LinkButton lbTrangThai = (LinkButton)ListViewAll.Items[i].FindControl("linkListName_G");
                if (chkHide != null)
                {
                    if (chkHide.Checked)
                    {
                        if (lbTrangThai.Text == "1")
                        {
                            lbThongBaoDuyet.Text = "Bạn đã cho số xe này ra rồi !";
                            OpenDialog("#thongbaochoxera");
                            upDatePanelChoXeRa.Update();
                        }
                        else
                        {
                            BindGridVehicleInOutDetail_Edit(Convert.ToInt32(ListViewAll.DataKeys[i].Value.ToString()));
                            lbThongBaoDuyet.Text = "Bạn có muốn cho xe này ra không !";
                            OpenDialog("#thongbaochoxera");
                            upDatePanelChoXeRa.Update();
                            cmdChoXeRa.Visible = true;
                            cmdClose.Text = "Bỏ qua";
                        }
                    }
                }
            }
        }
        protected void cmdExport_Click(object sender, EventArgs e)
        {
            
        }
       
        //---------------button-popup---------------------
        protected void imgrefesh_Click(object sender, ImageClickEventArgs e)
        {
            RefeshDropdownlist();
        }
        protected void imgSave_Click(object sender, ImageClickEventArgs e)
        {
            
            if (drSoXe.SelectedValue.ToString() == "-1")
            {
                lbThongBaoLoi.Text = "Vui lòng chọn số xe !";
                OpenDialog("#thongbao");
                updatePanelThongBao.Update();
            }
            if (drTaiXe.SelectedValue.ToString() == "-1")
            {
                lbThongBaoLoi.Text = "Vui lòng chọn tài xế !";
                OpenDialog("#thongbao");
                updatePanelThongBao.Update();
            }
           
            if (drKhachHang.SelectedValue.ToString() == "-1")
            {
                lbThongBaoLoi.Text = "Vui lòng chọn khách hàng !";
                OpenDialog("#thongbao");
                updatePanelThongBao.Update();
            }
            if (txtMaKhachHang.Text == "")
            {
                lbThongBaoLoi.Text = "Vui lòng chọn tên khách hàng để hiễn thị mã khách hàng !";
                OpenDialog("#thongbao");
                updatePanelThongBao.Update();
            }
            //-------------------------------------
            if (drSoXe.SelectedValue.ToString() != "-1"
                && drTaiXe.SelectedValue.ToString() != "-1"
                && drKhachHang.SelectedValue.ToString() != "-1"
                && txtMaKhachHang.Text !=""
                )
            {
                Insert();
            }
        }
        protected void cmdAgree_Click(object sender, EventArgs e)
        {
            
        }
        protected void cmdChoXeRa_Click(object sender, EventArgs e)
        {
            try
            {
                if (lbStatusID.Text == "1")
                {
                    lbThongBaoDuyet.Text = "Bạn đã cho xe này ra rồi  !";
                    OpenDialog("#thongbaochoxera");
                    upDatePanelChoXeRa.Update();
                }
                else
                {
                    VanTaiProperty.clsTMVehicleInfo_In_OutProperty obj = new clsTMVehicleInfo_In_OutProperty();
                    obj.RowID = int.Parse(lbID.Text);
                    obj.Status = 1;
                    obj.DateOut = DateTime.Now;
                    VanTaiBLL.clsTMVehicleInfo_In_OutBusiness.UpdateTMVehicleInfo_In_Out_Status(obj);
                    lbThongBaoDuyet.Text = "Cho xe ra thành công  !";
                    OpenDialog("#thongbaochoxera");
                    upDatePanelChoXeRa.Update();
                    cmdChoXeRa.Visible = false;
                    cmdBoQuaChoXeRa.Text = "Đóng lại";
                }
            }
            catch (Exception ex)
            {
                lbThongBaoDuyet.Text = ex.ToString();
                OpenDialog("#thongbaochoxera");
                upDatePanelChoXeRa.Update();
                cmdChoXeRa.Visible = false;
                cmdBoQuaChoXeRa.Text = "Đóng lại";
            }
        }
        protected void cmdBoQuaChoXeRa_Click(object sender, EventArgs e)
        {
            CloseDialog("#thongbaochoxera");
        }
        protected void cmdClose_Click(object sender, EventArgs e)
        {
            CloseDialog("#thongbaoxoa");
        }
        protected void cmdCloseThongBao_Click(object sender, EventArgs e)
        {
            CloseDialog("#thongbao");
        }
        //-------------list-view-----------------------
        protected void ListViewAll_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            try
            {
                HttpCookie cookie = Request.Cookies["UserLogin"];
                bool Edit = SecurityServices.HasPermisstion(StringContent.QuanLyThongTinXeRaVaoCong, int.Parse(cookie["RolesID"]), TypeaAudit.Edit);
                lbThongBaoLoi.Text = "";
                if (e.CommandName == "Accept")
                {
                    if (Edit == false)
                    {
                        imgSave.Visible = false;
                        string SenderId = ((HtmlInputHidden)e.Item.FindControl("hiddenId")).Value;
                        BindGridVehicleInOutDetail_Edit(int.Parse(SenderId));
                        OpenDialog("#thongtinravaocuaxe");
                        upNewUpdatePanel.Update();
                        imgSave.ToolTip = "Cập nhật";
                        flag = false;
                    }
                    else
                    {
                        imgSave.Visible = true;
                        string SenderId = ((HtmlInputHidden)e.Item.FindControl("hiddenId")).Value;
                        BindGridVehicleInOutDetail_Edit(int.Parse(SenderId));
                        OpenDialog("#thongtinravaocuaxe");
                        upNewUpdatePanel.Update();
                        imgSave.ToolTip = "Cập nhật";
                        flag = false;
                    }
                }
            }
            catch (Exception ex)
            {
                lbThongBaoLoi.Text = ex.ToString();
                OpenDialog("#thongbao");
                updatePanelThongBao.Update();
            }
        }
        protected void ListViewAll_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                LinkButton linkListName = (LinkButton)e.Item.FindControl("linkListName");
                LinkButton linkListName_G = (LinkButton)e.Item.FindControl("linkListName_G");
                string _jsDouble1 = ClientScript.GetPostBackClientHyperlink(linkListName, "");

                ListViewDataItem dataitem = (ListViewDataItem)e.Item;

                if (linkListName_G.Text == "0")
                {
                    linkListName_G.Text = "Không được ra";
                    HtmlTableRow cell = (HtmlTableRow)e.Item.FindControl("SetColor");
                    cell.BgColor = "Red";
                    cell.Attributes["class"] = "rowError";
                }
                if (linkListName_G.Text == "1")
                {
                    linkListName_G.Text = "Được phép ra";
                }
                linkListName.Attributes["ondblclick"] = _jsDouble1;
                linkListName.Attributes["onclick"] = "return false;";
            }
        }
        //-----------pagger-----------------------
        protected void DataPagerListAll_PreRender(object sender, EventArgs e)
        {
            DataPagerListAll.PageSize = 17;
            BindGridVehicleInOut();
        }
        //---------Check-all--------------
        protected void chkCheckAll_CheckedChanged(object sender, EventArgs e)
        {

        }
        //---------DropDownlist---------------------
        protected void drTrangThai_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (drTrangThai.SelectedValue.ToString() != "-1")
            {
                FillterTrangThai(drTrangThai.SelectedValue.ToString());
            }
            else
            {
                BindGridVehicleInOut();
            }
        }
        protected void drSoXe_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        protected void drTaiXe_SelectedIndexChanged(object sender, EventArgs e)
        {
        }
        protected void drKhachHang_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindGridDetail(int.Parse(drKhachHang.SelectedValue.ToString()));
        }
        //----------Them-Nhanh----------------
        protected void linkThemNhanhSoXe_Click(object sender, EventArgs e)
        {
            OpenDialog("#themnhanhsoxe");
        }
        protected void linkThemNhanhTaiXe_Click(object sender, EventArgs e)
        {
            OpenDialog("#themnhanhtaixe");
        }
        protected void linkThemNhanhKhachHang_Click(object sender, EventArgs e)
        {
            OpenDialog("#themnhanhkhachhang");
        }
        #endregion

        #region[Function]
        protected void BindGridVehicleInOut()
        {
            dtFillterTrangThai = clsVehicleInOut.TMVehicleInfo_Fillter(drTrangThai.SelectedValue.ToString());
            dtVehicleInOut = clsVehicleInOut.Search(txtSearch.Text);
            dtFilter = clsVehicleInOut.TMVehicleInfo_Fillter_Date(txtTuNgayNgayNhapKho.Text, txtDenNgayNhapKho.Text);
            if (txtTuNgayNgayNhapKho.Text == "" && txtDenNgayNhapKho.Text == "")
            {
                if (dtVehicleInOut != null && dtVehicleInOut.Rows.Count > 0)
                {
                    ListViewAll.DataSource = dtVehicleInOut;
                    ListViewAll.DataBind();
                    ListViewAll.Visible = true;
                    DataPagerListAll.Visible = true;
                }
                else
                {
                    ListViewAll.Visible = false;
                    DataPagerListAll.Visible = false;
                }
            }
            else
            {
                if (dtFilter != null && dtFilter.Rows.Count > 0)
                {
                    ListViewAll.DataSource = dtFilter;
                    ListViewAll.DataBind();
                    ListViewAll.Visible = true;
                    DataPagerListAll.Visible = true;
                }
            }
            #region
            //--------------------------------------
            if (drTrangThai.SelectedValue.ToString() != "")
            {
                if (dtFillterTrangThai != null && dtFillterTrangThai.Rows.Count > 0)
                {
                    ListViewAll.DataSource = dtFillterTrangThai;
                    ListViewAll.DataBind();
                    ListViewAll.Visible = true;
                    DataPagerListAll.Visible = true;
                }
            }
            #endregion
        }
        protected void BindGridVehicleInOutDetail_Edit(int id)
        {
            dtVehicleInOutDetail_Edit = clsVehicleInOut.BindGirdTMVehicleInfo_In_Out_Detail_Edit(id);
            if (dtVehicleInOutDetail_Edit != null && dtVehicleInOutDetail_Edit.Rows.Count > 0)
            {
                lbID.Text = dtVehicleInOutDetail_Edit.Rows[0]["STT"].ToString();
                lbIDXoa.Text = dtVehicleInOutDetail_Edit.Rows[0]["STT"].ToString();
                lbRowID.Text = dtVehicleInOutDetail_Edit.Rows[0]["STT"].ToString();
                lbStatusID.Text = dtVehicleInOutDetail_Edit.Rows[0]["Status"].ToString();
                drSoXe.SelectedValue = dtVehicleInOutDetail_Edit.Rows[0]["CarNo"].ToString();
                drKhachHang.SelectedValue = dtVehicleInOutDetail_Edit.Rows[0]["Customers_ID"].ToString();
                drTaiXe.SelectedValue = dtVehicleInOutDetail_Edit.Rows[0]["Member_ID"].ToString();
                txtContainer.Text = dtVehicleInOutDetail_Edit.Rows[0]["Container"].ToString();
                txtMaKhachHang.Text = dtVehicleInOutDetail_Edit.Rows[0]["Customers_Alias"].ToString();
                txtGhiChu.Text = dtVehicleInOutDetail_Edit.Rows[0]["Description"].ToString();
            }
        }
        protected void Insert()
        {
            //Insert
            if (flag)
            {
                InsertVehicleInOut();
            }
            else//Update
            {
                UpdateVehicleInOut();
            }
        }
        protected void InsertVehicleInOut()
        {
            try
            {
                VanTaiProperty.clsTMVehicleInfo_In_OutProperty obj = new clsTMVehicleInfo_In_OutProperty();
                obj.CustomerNo = int.Parse(drKhachHang.SelectedValue.ToString());
                obj.CarNo = int.Parse(drSoXe.SelectedValue.ToString());
                obj.Driver = int.Parse(drTaiXe.SelectedValue.ToString());
                obj.Container = txtContainer.Text;
                obj.DocumentDate = DateTime.Today;
                obj.DateIn = DateTime.Now;
                obj.Status = 0;
                VanTaiBLL.clsTMVehicleInfo_In_OutBusiness.InsertTMVehicleInfo_In_Out(obj);
                BindGridVehicleInOut();
                lbThongBaoLoi.Text = "Thêm mẫu tin thành công !";
                OpenDialog("#thongbao");
                updatePanelThongBao.Update();
                ClearTextbox();
            }
            catch (Exception ex)
            {
                lbThongBaoLoi.Text = ex.ToString();
                OpenDialog("#thongbao");
                updatePanelThongBao.Update();
            }
        }
        protected void UpdateVehicleInOut()
        {
            try
            {
                VanTaiProperty.clsTMVehicleInfo_In_OutProperty obj = new clsTMVehicleInfo_In_OutProperty();
                obj.RowID = int.Parse(lbID.Text);
                obj.CustomerNo = int.Parse(drKhachHang.SelectedValue.ToString());
                obj.CarNo = int.Parse(drSoXe.SelectedValue.ToString());
                obj.Driver = int.Parse(drTaiXe.SelectedValue.ToString());
                obj.Container = txtContainer.Text;
                obj.DocumentDate = DateTime.Today;
                obj.Status = 0;
                VanTaiBLL.clsTMVehicleInfo_In_OutBusiness.UpdateTMVehicleInfo_In_Out(obj);
                BindGridVehicleInOut();
                lbThongBaoLoi.Text = "Cập nhật mẫu tin thành công !";
                OpenDialog("#thongbao");
                updatePanelThongBao.Update();
            }
            catch (Exception ex)
            {
                lbThongBaoLoi.Text = ex.ToString();
                OpenDialog("#thongbao");
                updatePanelThongBao.Update();
            }
        }
        protected void Fillter(string DateBegin, string EndBegin)
        {
            dtFilter = clsVehicleInOut.TMVehicleInfo_Fillter_Date(txtTuNgayNgayNhapKho.Text, txtDenNgayNhapKho.Text);
            if (dtFilter != null && dtFilter.Rows.Count > 0)
            {
                ListViewAll.DataSource = dtFilter;
                ListViewAll.DataBind();

                ListViewAll.Visible = true;
                DataPagerListAll.Visible = true;

                StrAlert += "<div class='alert alert-success'>";
                StrAlert += "<a href='#' class='close' data-dismiss='alert'>&times;</a>";
                StrAlert += "Tìm thấy " + dtFilter.Rows.Count.ToString() + " mẫu tin !";
                StrAlert += "</div>";
            }
            else
            {
                StrAlert += "<div class='alert alert-error'>";
                StrAlert += "<a href='#' class='close' data-dismiss='alert'>&times;</a>";
                StrAlert += "Không tìm thấy mẫu tin nào !";
                StrAlert += "</div>";
                ListViewAll.Visible = false;
                DataPagerListAll.Visible = false;
            }
        }
        protected void FillterTrangThai(string TrangThai)
        {
            dtFillterTrangThai = clsVehicleInOut.TMVehicleInfo_Fillter(TrangThai);
            if (dtFillterTrangThai != null && dtFillterTrangThai.Rows.Count > 0)
            {
                ListViewAll.DataSource = dtFillterTrangThai;
                ListViewAll.DataBind();
                ListViewAll.Visible = true;
                DataPagerListAll.Visible = true;

            }
            else
            {
                ListViewAll.Visible = false;
                DataPagerListAll.Visible = false;

            }
        }
        //AutoComplate
        protected void Autocomplate()
        {
            dtAutoComplete = clsVehicleInOut.BindGirdTMVehicleInfo_In_Out();
            if (dtAutoComplete != null && dtAutoComplete.Rows.Count > 0)
            {
                foreach (DataRow dr in dtAutoComplete.Rows)
                {
                    if (string.IsNullOrEmpty(SuggestionList))
                    {
                        SuggestionList += "\"" + dr["Vehicle_Number"].ToString().Replace("\n", " ") + "\",";
                        SuggestionList += "\"" + dr["Customers_Name"].ToString().Replace("\n", " ") + "\",";
                        SuggestionList += "\"" + dr["FullNameMem"].ToString().Replace("\n", " ") + "\",";
                    }
                    else
                    {
                        SuggestionList += "\"" + dr["Vehicle_Number"].ToString().Replace("\n", " ") + "\",";
                        SuggestionList += "\"" + dr["Customers_Name"].ToString().Replace("\n", " ") + "\",";
                        SuggestionList += "\"" + dr["FullNameMem"].ToString().Replace("\n", " ") + "\",";
                    }
                }
            }
        }
        protected void Search(string keywords)
        {
            dtSearch = clsVehicleInOut.Search(keywords);
            if (dtSearch != null && dtSearch.Rows.Count > 0)
            {
                ListViewAll.DataSource = dtSearch;
                ListViewAll.DataBind();
                ListViewAll.Visible = true;
                DataPagerListAll.Visible = true;

                StrAlert += "<div class='alert alert-success'>";
                StrAlert += "<a href='#' class='close' data-dismiss='alert'>&times;</a>";
                StrAlert += "Tìm thấy " + dtSearch.Rows.Count.ToString() + " mẫu tin !";
                StrAlert += "</div>";
            }
            else
            {
                ListViewAll.Visible = false;
                DataPagerListAll.Visible = false;
                StrAlert += "<div class='alert alert-error'>";
                StrAlert += "<a href='#' class='close' data-dismiss='alert'>&times;</a>";
                StrAlert += "Không tìm thấy mẫu tin nào !";
                StrAlert += "</div>";
            }
        }
        protected void BindGridNumberVehicle()
        {
            dtVehicle = clsVehicle.BindGirdTMVehicle();
            if (dtVehicle != null && dtVehicle.Rows.Count > 0)
            {
                drSoXe.DataSource = dtVehicle;
                drSoXe.DataTextField = "Vehicle_Number";
                drSoXe.DataValueField = "Vehicle_ID";
                drSoXe.DataBind();
            }
        }
        protected void BindGridEmployer()
        {
            dtEmployer = clsEmployer.BindGirdTMMember();
            if (dtEmployer != null && dtEmployer.Rows.Count > 0)
            {
                drTaiXe.DataSource = dtEmployer;
                drTaiXe.DataTextField = "FullNameMem";
                drTaiXe.DataValueField = "Member_ID";
                drTaiXe.DataBind();
            }
        }
        protected void BindGridCustomer()
        {
            dtCustomer = clsCustomer.BindGirdTMCustomers();
            if (dtCustomer != null && dtCustomer.Rows.Count > 0)
            {
                drKhachHang.DataSource = dtCustomer;
                drKhachHang.DataTextField = "Customers_Name";
                drKhachHang.DataValueField = "Customers_ID";
                drKhachHang.DataBind();
            }
        }
        protected void BindGridDetail(int id)
        {
            dtCustomerDetail = clsCustomer.BindGirdTMCustomers_Detail_Edit(id);
            if (dtCustomerDetail != null && dtCustomerDetail.Rows.Count > 0)
            {
                txtMaKhachHang.Text = dtCustomerDetail.Rows[0]["Customers_Alias"].ToString();
            }
        }
        #endregion

        #region[OpenDialog]
        private void OpenDialog(string dialogId)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("$('" + dialogId + "').dialog('open');");
            ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),
               "scriptKey", sb.ToString(), true);
        }
        private void CloseDialog(string dialogId)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append("$('" + dialogId + "').dialog('close');");
            ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(),
               "scriptKey", sb.ToString(), true);
        }
        #endregion

        #region[ClearTextBox]
        protected void ClearTextbox()
        {
            txtContainer.Text = "";
            txtGhiChu.Text = "";

            drSoXe.SelectedIndex = -1;
            drTaiXe.SelectedIndex = -1;
            drKhachHang.SelectedIndex = -1;
        }
        #endregion

        #region[RefeshDropdownlist]
        protected void RefeshDropdownlist()
        {
            drSoXe.Items.Clear();
            drSoXe.Items.Add(new ListItem("--Vui lòng chọn số xe--", "-1"));
            BindGridNumberVehicle();

            drTaiXe.Items.Clear();
            drTaiXe.Items.Add(new ListItem("--Vui lòng chọn tài xế--", "-1"));
            BindGridEmployer();
        }
        #endregion

        #region[Permisstion]
        protected void CheckPermisstion()
        {
            HttpCookie cookie = Request.Cookies["UserLogin"];
            if (cookie != null)
            {
                bool Is_Page_All = SecurityServices.HasPermisstionPage(StringContent.QuanLyThongTinXeRaVaoCong, int.Parse(cookie["RolesID"]), true);
                if (Is_Page_All == true)
                {
                    bool AddNew = SecurityServices.HasPermisstion(StringContent.QuanLyThongTinXeRaVaoCong, int.Parse(cookie["RolesID"]), TypeaAudit.AddNew);
                    if (AddNew == false)
                    {
                        cmdAddNew.Visible = false;
                    }
                    else
                    {
                        cmdAddNew.Visible = true;
                    }
                    bool Edit = SecurityServices.HasPermisstion(StringContent.QuanLyThongTinXeRaVaoCong, int.Parse(cookie["RolesID"]), TypeaAudit.Edit);
                    if (Edit == false)
                    {
                        cmdEdit.Visible = false;
                    }
                    else
                    {
                        cmdEdit.Visible = true;
                    }
                    bool Del = SecurityServices.HasPermisstion(StringContent.QuanLyThongTinXeRaVaoCong, int.Parse(cookie["RolesID"]), TypeaAudit.Delete);
                    if (Del == false)
                    {
                        cmdDel.Visible = false;
                    }
                    else
                    {
                        cmdDel.Visible = true;
                    }
                }
                else
                {
                    Response.Redirect("error-page.aspx");
                }
            }
        }
        #endregion
    }
}